package android.dto;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;



public class TouchEvent extends ViewEvent{

	private static final long serialVersionUID = 1L;

	private List<Integer> pointers;
	private HashMap<Integer, ScreenCoordinates> current;
	private List<HashMap<Integer, ScreenCoordinates>> historical;
	private int action;
	
	public static final int ACTION_DOWN = 0;
	public static final int ACTION_UP = 1;
	public static final int ACTION_MOVE = 2;
	public static final int ACTION_CANCEL = 3;
	public static final int ACTION_OUTSIDE = 4;
	public static final int ACTION_POINTER_DOWN = 5;
	public static final int ACTION_POINTER_UP = 6;

	public TouchEvent() {
		pointers = new ArrayList<Integer>();
		current = new HashMap<Integer, ScreenCoordinates>();
		historical = new ArrayList<HashMap<Integer,ScreenCoordinates>>();
	}
	
	public int getPointerCount() {
		return pointers.size();
	}
	
	public int getHistorySize() {
		return historical.size();
	}
	
	public ScreenCoordinates getCurrent(int pointer) {
		return current.get(pointer);
	}
	
	public ScreenCoordinates getHistorical(int pointer, int pos) {
		return historical.get(pos).get(pointer);
	}
	
	public void addCurrent(int pointer, ScreenCoordinates sc) {
		if (!pointers.contains(pointer))
			pointers.add(pointer);
		current.put(pointer, sc);
	}
	
	public void addHistorical(int pointer, int pos, ScreenCoordinates sc) {
		if (!pointers.contains(pointer))
			pointers.add(pointer);
		if (pos >= historical.size())
			historical.add(pos, new HashMap<Integer, ScreenCoordinates>());
		historical.get(pos).put(pointer, sc);
	}

	public void setAction(int action) {
		this.action = action;
	}

	public int getAction() {
		return action;
	}
	
	public int getPointerId(int pointerIndex) {
		int id = -1;
		if (pointerIndex < pointers.size())
			id = pointers.get(pointerIndex);
		return id;
	}
	
	public int findPointerIndex(int pointer) {
		for (int i = 0; i < pointers.size(); i++)
			if (pointers.get(i) == pointer)
				return i;
		return -1;
	}

	public List<Integer> getPointers() {
		return pointers;
	}

}
